/**
 * Created by feifan on 2016/6/24.
 */
var express = require('express');
var fs=require('fs');
var router = express.Router();

router.get('/:id', (req, res)=> {
    db.findOne('articles', {id:parseInt(req.params.id)}, (data)=> {
        if(data){
            let result=JSON.parse(JSON.stringify(data));
            fs.readFile('./articles/'+data.id+'.html','utf8', (err, html) => {
                if (err){
                    log(err);
                    result.content="error";
                }else{
                    result.content=html;
                }

                res.json(result);
            });
        }else{
            res.end();
        }
    });
});

module.exports = router;